'''
Created on May 18, 2011

@author: james
'''        

from AggregateCall import AggregateCall
 
class Aggregate:
    def __init__(self, display = False):
        self.output = ""
        self.total = 0
        self._display = display
        
    def mapCalls(self, x):
        self.output += "%d, " % x
        self.total += x
        
    def mapMonth(self, x):
        a = Aggregate()
        map(a.mapCalls, x)
        self.output += "%s = %d, " % (a.output, a.total)
        self.total += a.total
        
    def mapDoctor(self, x):
        a = Aggregate()
        map(a.mapMonth, x)
        self.output = "%s = %d, " % (a.output, a.total)
        #self.total += a.total
        if self._display: print self.output
        
class ReduceCalls:
        
    def mapMonth(self, x):
        callCounts = [0, 0, 0, 0]
        for m in x:
            #callCounts = [0 for i in range(len(m)) ]
            for i in range(len(m)):
                callCounts[i] += m[i]
        return callCounts
        
    def mapDoctor(self, x):
        
        return [ self.mapMonth(x[i]) for i in range(len(x)) ] 
        
        #l = map(self.mapMonth, x)
        #return l
    
def printCall(tally): 
    a = Aggregate(True)
    map(a.mapDoctor, tally)
                
                
callTally = [
                            [ [2, 0, 3, 1], [2, 0, 1, 0], [4, 1, 1, 0], [2, 1, 2, 0], [3, 1, 2, 0] ],
                            [ [4, 0, 2, 0], [2, 1, 1, 0], [4, 1, 1, 0], [2, 0, 2, 0], [3, 1, 1, 0] ],
                            [ [3, 0, 2, 0], [3, 0, 2, 0], [3, 1, 1, 0], [3, 0, 1, 0], [3, 1, 2, 0] ],
                            [ [3, 1, 0, 0], [2, 2, 2, 1], [3, 0, 2, 0], [4, 1, 1, 0], [2, 0, 2, 1] ],
                            [ [3, 0, 2, 0], [2, 0, 2, 0], [3, 0, 1, 0], [2, 2, 2, 0], [4, 0, 2, 0] ],
                            [ [2, 2, 2, 1], [4, 1, 1, 0], [2, 1, 2, 0], [3, 0, 2, 1], [2, 1, 1, 0] ],
                        ]

newCallTally = [ [4, 1, 1, 0], [2, 0 ,3, 0] ]

print callTally
printCall(callTally)

print map(AggregateCall.sumCalls, callTally)
#r = ReduceCalls()
#print map(r.mapMonth, callTally)
#print r.mapDoctor(callTally)

'''
for doctorId in range(len(callTally)):
    callTally[doctorId].append( newCallTally[doctorId] )
    
print callTally
printCall(callTally)
'''